package playlistData;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

public class PlaylistMap {
	private HashMap<String, String> playlist;
	
	public PlaylistMap(HashMap<String, String> playlist) {
		loadPlaylist(playlist);
	}
	
	public void loadPlaylist(HashMap<String, String> playlist) {
		this.playlist = playlist;
	}
	
	/**
	 * 
	 * Ritorna i valori contenuti nella Playlist
	 * 
	 * @return list
	 */
	public String[] getNames() {

		Collection<String> values = playlist.values();
		String[] list = new String[values.size()];
		int i = 0;
		for (String value : values) {
			list[i] = value;
			i++;
		}
		return list;
	}

	/**
	 * 
	 * @return playlist
	 */
	public HashMap<String, String> getPlaylist() {
		return playlist;
	}

	/**
	 * 
	 * @param name
	 * @return ritorna il percorso dell'immagine se presente nella mappa, null
	 *         in caso contrario.
	 */
	public String getPathByName(String name) {
		Iterator<Entry<String, String>> it = playlist.entrySet().iterator();
		while (it.hasNext()) {
			Map.Entry<String, String> entry = it.next();
			if (entry.getValue().compareTo(name) == 0) {
				return entry.getKey();
			}
		}
		return null;

	}
}
